package cjm.task5.service;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class AnalysisServiceImpl implements AnalysisService{

    @Override
    public List<String> getData1() throws IOException {
        Document document = Jsoup.connect("http://m.dg.bendibao.com/news/gelizhengce/fengxianmingdan.php").get();
        Elements elements1 = document.select(".height").select("span");
        List<String> list1 = new ArrayList<String>();//高风险地区
        for (Element element : elements1) {
            if(element.text().length()>8){
                list1.add(element.text());
            }
        }
        return list1;
    }

    @Override
    public List<String> getData2() throws IOException {
        Document document = Jsoup.connect("http://m.dg.bendibao.com/news/gelizhengce/fengxianmingdan.php").get();
        Elements elements2 = document.select(".middle").select("span");
        List<String> list1 = new ArrayList<String>();//中风险地区
        for (Element element : elements2) {
            if(element.text().length()>8){
                list1.add(element.text());
            }
        }
        return list1;
    }
}
